package studio.raptor.dispatcher.server.metrics;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.stereotype.Component;

/**
 * @author jack
 * @since 1.0
 */
@Aspect
@Component
public class ConsumerMetricsAspect {

  @Autowired
  private GaugeService gaugeService;
  @Autowired
  private CounterService counterService;

//  @Around("execution(* studio.raptor.dispatcher.server.handler.*.*(..))")
//  public void latencyService(ProceedingJoinPoint pjp) throws Throwable {
//    long start = System.currentTimeMillis();
//    pjp.proceed();
//    long end = System.currentTimeMillis();
//    gaugeService.submit(pjp.getSignature().toString(), end - start);
//  }


  @Before("execution(* studio.raptor.dispatcher.server.handler.consumption.PersistEventHandler.process(..))")
  public void countServiceInvoke(JoinPoint joinPoint) {
    counterService.increment(joinPoint.getSignature() + "");
  }

}
